package com.yunyao.dao.service.bamu.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.model.BamuReconciliationOrder;
import com.yunyao.dao.mapper.BamuReconciliationOrderMapper;
import com.yunyao.dao.model.BamuReconciliationSettlementOrder;
import com.yunyao.dao.model.BamuSpReconciliationOrder;
import com.yunyao.dao.service.bamu.IBamuReconciliationOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账订单表 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class BamuReconciliationOrderServiceImpl extends ServiceImpl<BamuReconciliationOrderMapper, BamuReconciliationOrder> implements IBamuReconciliationOrderService {

    @Override
    public List<BamuReconciliationOrder> listByIdsDeleted(List<String> soSupplyIdList) {
        // 检查对账ID列表是否为空，如果为空则直接返回空列表
        if (CollectionUtils.isEmpty(soSupplyIdList)) {
            return List.of();
        }

        // 创建查询条件封装Lambda表达式，用于筛选特定条件的对账结算单
        LambdaQueryWrapper<BamuReconciliationOrder> wrapper =
                new LambdaQueryWrapper<BamuReconciliationOrder>()
                        // 条件1：清单ID在给定的列表中
                        .in(BamuReconciliationOrder::getSupplyId, soSupplyIdList)
                        // 条件2：对账单的删除状态为未删除
                        .eq(BamuReconciliationOrder::getIsDeleted, DataDeletedStatus.NO.getType());

        // 使用封装的查询条件，查询并返回对账单列表
        return list(wrapper);
    }

    @Override
    public List<BamuReconciliationOrder> listByReconciliationSettlementIdDeleted(String reconciliationId) {
        // 检查对账ID列表是否为空，如果为空则直接返回空列表
        if (StringUtils.isBlank(reconciliationId)) {
            return List.of();
        }

        // 创建查询条件封装Lambda表达式，用于筛选特定条件的对账结算单
        LambdaQueryWrapper<BamuReconciliationOrder> wrapper =
                new LambdaQueryWrapper<BamuReconciliationOrder>()
                        // 条件1：对账ID在给定的列表中
                        .in(BamuReconciliationOrder::getReconciliationId,
                                reconciliationId)
                        // 条件2：对账结算单的删除状态为未删除
                        .eq(BamuReconciliationOrder::getIsDeleted,
                                DataDeletedStatus.NO.getType());
        return list(wrapper);
    }

    @Override
    public void deletedByReconciliationIdList(List<String> sosupplyIdList) {
        if (CollectionUtils.isEmpty(sosupplyIdList)) {
            return;
        }
        LambdaUpdateWrapper<BamuReconciliationOrder> wrapper =
                new LambdaUpdateWrapper<BamuReconciliationOrder>()
                        .in(BamuReconciliationOrder::getSupplyId,
                                sosupplyIdList)
                        .eq(BamuReconciliationOrder::getIsDeleted,
                                DataDeletedStatus.NO.getType())
                        .set(BamuReconciliationOrder::getIsDeleted,
                                DataDeletedStatus.YES.getType());
        update(wrapper);
    }
}
